#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define getchar() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=getchar();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        x*=f;
    }
}
using namespace IO;
const int N=1e6+5;
int n,k,a[N],ans,f[N];
vector<int> G[N];
void dfs(int p){
	for(int v:G[p]){
		dfs(v);
		f[p]=max(f[p],f[v]+1);
	}
	if(f[p]==k-1) ans+=(a[p]!=1),f[p]=-1e9;
}
int main(){
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	read(n),read(k);
	for(int i=1;i<=n;++i) read(a[i]);
	if(a[1]!=1) ++ans,a[1]=1;
	for(int i=2;i<=n;++i) G[a[i]].push_back(i);
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

